﻿@using ZBJF.Warranty.WebProvider
@{
    ViewBag.Title = "Index";
}
@section Header{
    @Scripts.Render("~/bundles/datatable")
    @Styles.Render("~/Content/datatable")
}
<ul class="nav nav-tabs">
    <li class="active"><a href="/AccessoriesLevelIndex/">配件等级列表</a></li>
    <li class="Add-R"><a href="/AccessoriesLevel/AccessoriesLevelEdit/0">添加配件等级</a></li>
</ul>
<form id="searchForm" class="breadcrumb form-search">
    <div>
        <label>设备类型：</label>
        @Html.DropDownList("ProductTypeID", ConvertToSelector.Instance.ProductTypeConvertToSelectList())
        <label>配件类型：</label>
        <select id="AccessoriesTypeID" name="AccessoriesTypeID">
            <option>请选择</option>
        </select>
        <label>配件等级名称：</label><input id="accessoriesLevelName" name="accessoriesLevelName" class="input-medium" placeholder="请输入配件等级名称" type="text" value="" maxlength="20" />
        <input id="btnSubmit" class="btn btn-primary Search-R" type="button" value="查询" onclick="search();">
    </div>
</form>
<div class="table-responsive dataTables_wrapper">
    <table id="accessoriesLevelList" class="table table-striped table-bordered table-hover">
        <thead>
            <tr>
                <th width="20">序号</th>
                <th width="100">设备类型</th>
                <th width="100">配件类型</th>
                <th width="100">配件等级</th>
                <th width="100">配件编码</th>
                <th width="80">是否启用</th>
                <th width="80">最后修改人</th>
                <th width="80">最后修改时间</th>
                <th width="60">操作</th>
            </tr>
        </thead>
    </table>
</div>
@section scripts{
    @Scripts.Render("~/Bundles/ImagePreview")
    <script src="~/Scripts/moment.js"></script>
    <script type="text/javascript">
        var isSearch = false;
        $(function () {
            var objTable = $("#accessoriesLevelList")
                .dataTable({
                    fnDrawCallback: function () {
                        ControlPermissionOperate();
                    },
                    "sAjaxSource": "/AccessoriesLevel/AccessoriesLevelList",
                    aoColumns: [
                        {
                            "mData": null, "bSortable": false, "fnRender": function (nRow) {
                                return nRow.iDataRow + 1;
                            }
                        },
                        { "mData": "ProductName", "bSortable": false },
                        { "mData": "AccessoriesName", "bSortable": false },
                        {
                            "mData": "AccessoriesLevelName", "bSortable": false, "fnRender": function (nRow) {
                                return "<a class='Edit-R' href='/AccessoriesLevel/AccessoriesLevelEdit/" + nRow.aData.ID + "' title='edit'>" + nRow.aData.AccessoriesLevelName + "</a>";
                            }
                        },
                         { "mData": "AccessoriesLevelCode" },
                         { "mData": "IsAvailable" },
                         { "mData": "LastModifyBy", "bSortable": false },
                         {
                             "mData": "LastModifyTime", "fnRender": function (nRow) {
                                 return moment(nRow.LastModifyTime).format('YYYY-MM-DD HH:mm:ss');
                             }
                         },
                        { "mData": "ID", "bSortable": false }
                    ],
                    "fnRowCallback": function (nRow, aData, iDisplayIndex) {
                        $('td:eq(5)', nRow).html(aData.IsAvailable ? bootStrapOkIncon : bootStrapRemoveIncon);
                        var html = "<a class='Edit-R' href='/AccessoriesLevel/AccessoriesLevelEdit/" + aData.ID + "' title='edit'><i class='icon-edit'></i></a>";
                        html += "<a class='Edit-R' href=\"javascript:UpdateStatus('" + aData.ID + "'," + !aData.IsAvailable + ",'/AccessoriesLevel/UpdateStatus','accessoriesLevelList')\" title='" + (aData.IsAvailable ? "禁用" : "启用") + "'>" + (aData.IsAvailable ? bootStrapRemoveIncon : bootStrapOkIncon) + "</a>";
                        $('td:eq(8)', nRow).html(html);
                    }
                });
            imgPreview();


            //设备类型选择事件
            $("#ProductTypeID").on("change", function () {
                var _value = $(this).val();
                //设置配件类型
                setSelectData("/AccessoriesType/GetAccessoriesType", "GET", "AccessoriesTypeID", { ProductTypeId: _value }, "ID", "AccessoriesName", true);

            })
        });

        function imgPreview() {
            setTimeout(function () { $("img.preview").preview(); }, 500);
        }
        function search() {
            /*给查询对象赋值*/
            queryParamList.AccessoriesLevelName = ($("#accessoriesLevelName").val()).trim();
            queryParamList.ProductTypeID = $("#ProductTypeID").val();
            queryParamList.AccessoriesTypeID = $("#AccessoriesTypeID").val();
            $("#accessoriesLevelList").dataTable().fnDraw();
            imgPreview();
        }

        //数据后台地址 | 请求方式（post/get） | select标签的ID | 请求参数 | Value对应的字段名称 | Text对应的字段名称 | 是否有默认选项 true/false
        function setSelectData(url, postType, selectId, params, valueName, textName, hasDefault) {
            //加载所有的带接入列表
            $.ajax({
                type: postType,
                url: url,
                dataType: "json",
                data: params,
                success: function (data) {
                    if (!data.Result) {
                        alert("初始化数据失败");
                        return;
                    }
                    var _data = data.Data;
                    var _html = "";
                    if (hasDefault == true) {
                        _html += "<option value=''>请选择</option>";
                    }
                    if (_data && _data.length > 0) {
                        _data.forEach(function (item) {
                            _html += "<option value='" + item[valueName] + "'>" + item[textName] + "</option>";
                        })
                    }
                    $("#" + selectId).html(_html);
                }
            });
        }
    </script>
}


